<?php
	/**
		Custom WP Query
		Access & build a menu in the sidebar of "narrow by" links generated from the Narrow By Links ACF
	**/
?>

<?php if(is_tax()) { ?>
<?php
    $object = $wp_query->queried_object;
    $termID = 'product_cat_'  . ($object->term_id);
?>
    <?php if(get_field('narrowbylinks', $termID)) { ?>
    <h3 class="widget-title">Narrow By</h3>
    <div class="homesidebarCategories">
    	<ul class="product-categories">
        <?php while(has_sub_field('narrowbylinks', $termID)) : ?>
        <li class="cat-item"><a href="/../<?php the_sub_field('narrowbyurl'); ?>"><?php the_sub_field('narrowbytitle'); ?></a></li>
        <?php endwhile; ?>
    </ul>
    </div>
    <?php wp_reset_query(); ?>
    <?php } ?>
    
<?php } else { ?>

    <?php 
	if (get_field('narrowbylinks')) { 
    ?>

	<h3 class="widget-title">Narrow By</h3>
    <div class="homesidebarCategories">
    	<ul class="product-categories">
    		<?php while(has_sub_field('narrowbylinks')) : ?>
        		<li class="cat-item"><a href="/../<?php the_sub_field('narrowbyurl'); ?>"><?php the_sub_field('narrowbytitle'); ?></a></li>
        	<?php endwhile; ?>
    	</ul>
    </div>

    <?php } ?>
<?php } ?>